<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/31
 * Time: 17:12
 */
namespace  app\admin\validate;

use think\Request;
use think\Validate;

class BaseValidate extends Validate {

    public function goCheck(){
        $request = Request::instance();
        $params = $request->param();
        $result = $this->check($params);
        if(!$result){
            ajaxReturn(['code'=>400,'msg'=>$this->getError()]);
            return false;
        }
        return true;
    }

    /**
     * 判断是否为正整数
     * @param $value
     *
     * @return bool
     */
    protected function isPositveInteger($value){
        if(!preg_match("/^[1-9][0-9]*$/",$value)){
            return false;
        }
        return true;
    }

    /**
     * 判断是否为空
     * @param $value
     *
     * @return bool
     */
    protected function isNotEmpty($value){
        if(empty($value)){
            return false;
        }
        return true;
    }

    /**判断手机格式是否正确
     * @param $mobile
     * @return bool
     */
    protected  function isMobile($mobile){
        if (!is_numeric($mobile)) {
            return false;
        }
        return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $mobile) ? true : false;
    }
}